<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>回收站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/dist/css/layui.css"  media="all">
    <link rel="stylesheet" href="css/bootstrap.min.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="demoTable">
    <button type="button" class="layui-btn layui-btn-danger" id="removeFile">
        <i class="layui-icon">&#xe640;</i>批量删除
    </button>
    &nbsp;&nbsp;
    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off" placeholder="请输入搜索内容">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>

<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>

<!--<span th:text="${session.users.realName}"></span> -->

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="check">预览</a>
    <a lay-event="detail"><i class="layui-icon layui-icon-download-circle" style="font-size: 20px;"></i></a>
    <a lay-event="more"><i class="layui-icon layui-icon-share" style="font-size: 20px;"></i></a>
    <a lay-event="more"><i class="layui-icon layui-icon-delete" style="font-size: 20px;"></i></a>
</script>

<script src="layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的,下面几行需要再进行调整！！！！ -->

<script th:inline='none'>
    layui.use('table', function(){
        var table = layui.table;
        var $=layui.$;
        $("#addFolderDiv").hide();
        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            ,url: 'getAllFile'
            ,cols: [[
                {checkbox: true, fixed: true}
                ,{field:'fileName', title: '文件名',templet:'#filenameDev',fixed:true}//fixed内容为自己添加
                ,{field:'fileSize', title: '文件大小', width:200,sort: true}
                ,{field:'fileType', title: '文件类型', width:200,sort: true}
                ,{field:'uploadTime', title: '上传时间', width:300,sort: true,templet:"<div>{{layui.util.toDateString(d.uploadTime,'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200,sort: true}
            ]]
            ,page: true//开启分页
            ,id:'testReload'
            ,parseData: function (res) {
                console.log(res);
                return {
                    "code": 0,
                    "msg": res.msg,
                    "count": res.count,
                    "data": res.data
                };
            }
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        id: demoReload.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    layui.use(['upload','layer'],function () {
        var upload = layui.upload;
        var layer = layui.layer;
        //执行实例
        upload.render({
            elem: '#uploadFile' //绑定元素
            ,url: 'uploadFile' //上传接口
            ,accept:'file'//可上传文件
            ,done: function(res){
                //上传完毕回调
                if(res.code==0){
                    layer.open({
                        title:'提示信息'
                        ,content:'导入成功！'
                        ,btn:['确认']
                        ,yes: function(){
                            window.location.reload();//刷新页面
                        }
                    });
                }
                else{
                    layer.alert(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                layer.alert("系统出错，请联系管理员");
            }
        });
    })
</script>

<script>
    layui.use('table', function() {
        var table = layui.table;
        table.on('tool(user)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === "check") {
                window.open("check?data.fileAbsolute=" + data.fileAbsolute);
            }
        })
    });
</script>

</body>
</html>